<?php

namespace App\Models;

use App\Enum\VehicleConfigEnum;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;

class ConfigModel extends Model
{
    //
    protected $table = 'config';

    //黑名单
    protected $guarded = [];

    protected $dateFormat = 'U';
    protected $redis;

    public static function getVehicleType()
    {
        $redis = app('redis.connection');
        $data = $redis->get(VehicleConfigEnum::VEHICLE_CONFIG_REDIS_KEY);
        if( !empty($data) ) return $data;

        $result =  static::query()->where(['name'=>'vehicle_type'])->value('value');
        $redis->set(VehicleConfigEnum::VEHICLE_CONFIG_REDIS_KEY, $result, 'EX', VehicleConfigEnum::VEHICLE_CONFIG_REDIS_TIMEOUT_HOURLY);
        return $result;
    }
    public static function getVehicleUseType()
    {
        $redis = app('redis.connection');
        $data = $redis->get(VehicleConfigEnum::VEHICLE_USE_CONFIG_REDIS_KEY);
        if( !empty($data) ) return $data;

        $result = static::query()->where(['name'=>'vehicle_use_type'])->value('value');
        $redis->set(VehicleConfigEnum::VEHICLE_USE_CONFIG_REDIS_KEY, $result, 'EX', VehicleConfigEnum::VEHICLE_CONFIG_REDIS_TIMEOUT_HOURLY);
        return $result;
    }
}
